/**
 * @FileName: VnetH5Controller.java
 * @Author
 * @Description:
 * @Date 2016年8月31日 下午2:59:28
 * @CopyRight ZTE Corporation
 */
package cn.hpclub.server.controller.h5;

import java.util.Date;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.hpclub.server.constant.H5ApiConstant;
import cn.hpclub.server.model.MemberOrg;
import cn.hpclub.server.model.VnetRecord;

public class VnetH5Controller extends BaseH5Controller{
    private static Logger       logger     = LoggerFactory.getLogger(VnetH5Controller.class);
    private static final String V_CODE     = "vCode";
    private static final String V_NAME     = "vName";

    private static final String V_TYPE     = "vType";
    private static final String OP_TYPE    = "opType";
    private static final String V_MEMBER   = "vMember";
    private static final String V_SHORT    = "vShort";
    private static final String V_PKG_RATE = "vPkgRate";
    private static final String V_PKG_NAME = "vPkgName";
    private static final String USER_ID    = "userid";
    private static final String REMARK     = "remark";

    public void operate(){
        JSONObject result = setResponseObj(H5ApiConstant.ResultCode.FAIL_CODE, H5ApiConstant.Msg.PARA_ILLEGAL,
                                           H5ApiConstant.Msg.EMPTY);

        try{
            MemberOrg member = MemberOrg.dao.getActiveMemberbyUserId(getParaToInt(USER_ID));
            if(member == null){
                throw new Exception("营业员用户不存在！");
            }

            VnetRecord r = getModel(VnetRecord.class);
            r.set(VnetRecord.V_TYPE, getParaToInt(V_TYPE));
            r.set(VnetRecord.V_CODE, getPara(V_CODE));
            r.set(VnetRecord.V_NAME, getPara(V_NAME));
            r.set(VnetRecord.OP_TYPE, getParaToInt(OP_TYPE));
            r.set(VnetRecord.V_MEMBER, getPara(V_MEMBER));
            r.set(VnetRecord.V_SHORT, getPara(V_SHORT));
            r.set(VnetRecord.V_PKG_NAME, getPara(V_PKG_NAME));
            r.set(VnetRecord.V_PKG_RATE, getPara(V_PKG_RATE));
            r.set(VnetRecord.USER_ID, getParaToInt(USER_ID));
            r.set(VnetRecord.USER_NAME, member.getStr(MemberOrg.NAME));
            r.set(VnetRecord.USER_MOBILE, member.getStr(MemberOrg.USER_NAME));
            r.set(VnetRecord.TIME, new Date());

            r.set(VnetRecord.REMARK, "");
            r.save();

            result = setResponseObj(H5ApiConstant.ResultCode.SUCCESS_CODE, H5ApiConstant.Msg.EMPTY,
                                    H5ApiConstant.Msg.EMPTY);

        }
        catch(Exception e){
            e.printStackTrace();
            logger.error("error:" + e.getMessage());
            result = setResponseObj(H5ApiConstant.ResultCode.EXCEPTION_CODE,
                                    e.getMessage() == null ? "" : e.getMessage(), H5ApiConstant.Msg.EMPTY);
        }
        finally{
            renderText(result.toString());
        }

    }
}
